import os
from dotenv import load_dotenv

load_dotenv() # 从 .env 文件加载环境变量

class Config:
    # 数据库配置
    SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL', 'sqlite:///app.db')
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SECRET_KEY = os.getenv('SECRET_KEY', 'a-very-secret-key')
    SERVER_NAME = os.getenv('SERVER_NAME')
    
    # LDAP 配置 (从 .env 文件读取)
    LDAP_ENABLED = os.getenv('LDAP_ENABLED', 'True').lower() in ('true', '1', 't')
    LDAP_SERVER = os.getenv('LDAP_SERVER')
    LDAP_BIND_DN = os.getenv('LDAP_BIND_DN')
    LDAP_BIND_PASSWORD = os.getenv('LDAP_BIND_PASSWORD')
    LDAP_BASE_DN = os.getenv('LDAP_BASE_DN')
    LDAP_USER_OU = os.getenv('LDAP_USER_OU')
    LDAP_GROUP_OU = os.getenv('LDAP_GROUP_OU')

    # --- 邮件配置 ---
    MAIL_SERVER = os.getenv('MAIL_SERVER')
    MAIL_PORT = int(os.getenv('MAIL_PORT', 465))
    MAIL_USE_TLS = os.getenv('MAIL_USE_TLS') == 'True'
    MAIL_USE_SSL = os.getenv('MAIL_USE_SSL') == 'True' # <-- 确保这一行存在
    MAIL_USERNAME = os.getenv('MAIL_USERNAME')
    MAIL_PASSWORD = os.getenv('MAIL_PASSWORD')
    MAIL_DEFAULT_SENDER = os.getenv('MAIL_USERNAME')
